interface Order {
    execute(): void;
}

class Stock {
    private name: string = 'ABC';
    private quantity: number = 10;
    public buy(): void {
        console.log('buy', this);
    }
    public sell(): void {
        console.log('sell', this);
    }
}

class BuyStock implements Order {
    private stock: Stock;
    public constructor(stock: Stock) {
        this.stock = stock;
    }
    public execute(): void {
        this.stock.buy();
    }
}

class SellStock implements Order {
    private stock: Stock;
    public constructor(stock: Stock) {
        this.stock = stock;
    }
    public execute(): void {
        this.stock.sell();
    }
}

class Broker {
    private orderList: Order[] = [];
    public takeOrder(order: Order): void {
        this.orderList.push(order);
    }
    public placeOrders(): void {
        while (this.orderList.length > 0) {
            const order = this.orderList.shift();
            if (order !== undefined) {
                order.execute();
            }
        }
    }
}

function main() {
    const stock: Stock = new Stock();
    const buyStock: BuyStock = new BuyStock(stock);
    const sellStock: SellStock = new SellStock(stock);
    const broker: Broker = new Broker();
    broker.takeOrder(buyStock);
    broker.takeOrder(sellStock);
    broker.placeOrders();
}

main();
